<?php
class ReaderModel extends Model{
	//分页查询所有读者
	public function getAllReaders($offset,$pagesize){
		$sql="SELECT tb_reader.*,b.* FROM `tb_reader` 
		LEFT JOIN (SELECT id AS typeid,name as typename,number FROM tb_readertype) as b 
		ON tb_reader.typeid=b.typeid order by id desc limit {$offset},{$pagesize}";
		return $this->db->getAll($sql);
	}
	
	//通过条形码查询一位读者
	public function getOneReader($barcode){
		$sql="SELECT tb_reader.*,b.* FROM `tb_reader`
		LEFT JOIN (SELECT id AS typeid,name as typename,number FROM tb_readertype) as b
		ON tb_reader.typeid=b.typeid where barcode={$barcode}";
		return $this->db->getRow($sql);
	}
	//通过读者id查询一位读者
	public function getOneReader1($readerid){
		$sql="SELECT tb_reader.*,b.* FROM `tb_reader`
		LEFT JOIN (SELECT id AS typeid,name as typename,number FROM tb_readertype) as b
		ON tb_reader.typeid=b.typeid where id={$readerid}";
		return $this->db->getRow($sql);
	}
}